import apiClient from '@/api/client'
import type { ApiResponse, PageResult } from '@/types/common'
import type { Moment, CreatedTimeItem } from '../types'

// 获取 Moments 列表
export const getMomentsList = async (isFavorite?: boolean, time?: string, pageNo?: number, pageSize?: number): Promise<PageResult<Moment>> => {
  const params: any = {}
  if (isFavorite !== undefined) {
    params.isFavorite = isFavorite
  }
  if (time) {
    params.time = time
  }
  if (pageNo !== undefined) {
    params.pageNo = pageNo
  }
  if (pageSize !== undefined) {
    params.pageSize = pageSize
  }
  const response = await apiClient.get<ApiResponse<PageResult<Moment>>>('/moments/list', { params })
  return response.data.data
}

// 获取 Moment 详情
export const getMomentDetail = async (id: string): Promise<Moment> => {
  const response = await apiClient.get<ApiResponse<Moment>>(`/moments/${id}`)
  return response.data.data
}

// 创建 Moment
export const createMoment = async (data: { createdTime?: string; title: string; content: string }): Promise<Moment> => {
  const response = await apiClient.post<ApiResponse<Moment>>('/moments/create', data)
  return response.data.data
}

// 获取创建时间列表
export const getCreatedTimeList = async (): Promise<CreatedTimeItem[]> => {
  const response = await apiClient.get<ApiResponse<CreatedTimeItem[]>>('/moments/created-time/list')
  return response.data.data
}
